Skip to content

perf(daemon): cache getKnownRigs() per tick and atomic rigs.json writes#3489

Open
jw409 wants to merge 1 commit intogastownhall:mainfrom
jw409:fix/cache-known-rigs-atomic-writes-3466
Open

perf(daemon): cache getKnownRigs() per tick and atomic rigs.json writes#3489
jw409 wants to merge 1 commit intogastownhall:mainfrom
jw409:fix/cache-known-rigs-atomic-writes-3466

Conversation

@jw409
Copy link
Copy Markdown
Contributor

@jw409 jw409 commented Apr 2, 2026

Summary

  • Cache getKnownRigs() result per heartbeat tick instead of reading mayor/rigs.json on every call — eliminates 10+ redundant disk reads per tick
  • Replace direct os.WriteFile on rigs.json in the doctor package with util.AtomicWriteFile (write-to-temp-then-rename) — prevents concurrent readers from seeing zero-byte or partial content

Changes

  • internal/daemon/daemon.go — Add cachedKnownRigs/knownRigsCached fields to Daemon struct; getKnownRigs() returns cached result on subsequent calls within the same tick. Cache is invalidated at the start of each heartbeat() call. All access is single-goroutine (the main for/select loop), so no mutex needed.
  • internal/doctor/workspace_check.go — Replace two os.WriteFile calls for rigs.json with util.AtomicWriteFile, which already exists in the codebase and uses write-to-temp-then-rename.

Notes

  • The existing util.AtomicWriteFile helper (and copyFileIfNewer in session/registry.go) already use the temp-file-then-rename pattern. This PR extends that pattern to the two remaining non-atomic write sites in the doctor package.
  • Could not run go build locally (go.mod requires go 1.25.8, local toolchain is 1.25.2). Changes are minimal and mechanically correct — CI will validate.

Fixes #3466


🇺🇸 Reid Wiseman — Commander
🇺🇸 Victor Glover — Pilot
🇺🇸 Christina Koch — Mission Specialist
🇨🇦 Jeremy Hansen — Mission Specialist

Artemis II. Open source for all — on this planet and beyond it.

…writes

Cache the result of getKnownRigs() within each heartbeat tick to eliminate
10+ redundant reads of mayor/rigs.json per cycle. The cache is invalidated
at the start of each heartbeat so changes are picked up between ticks.

Replace direct os.WriteFile calls for rigs.json in the doctor package with
util.AtomicWriteFile (write-to-temp-then-rename) to prevent concurrent
readers from seeing zero-byte or partial content.

Fixes gastownhall#3466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/needs-triage Inbox — we haven't looked at it yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant